#ifndef ABSTRACTMAPPINGWINDOW_H
#define ABSTRACTMAPPINGWINDOW_H

#include "ui_mappingdialog.h"
#include <QtGui/QMainWindow>
#include <QString>
#include <vector>
#include <string>


class QPushButton;
class QVBoxLayout;
class QHBoxLayout;
class DiagramScene;
class AbstractManager;
class NodeItem;
class NodePort;
class QGraphicsView;
class QTreeWidgetItem;
class QTreeWidget;


class AbstractMappingWindow : public QMainWindow
{
	Q_OBJECT

public:
	const static int VM_BUTTON_WIDTH  = 50;
	const static int VM_BUTTON_HEIGHT = 50;
	const static int SCENE_WIDTH = 2000;
	const static int SCENE_HEIGHT = 2000;

	AbstractMappingWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
	virtual ~AbstractMappingWindow();
	DiagramScene* currentScene();
	QTabWidget* mappingTreeTabWidget();
	NodeItem* currentSelectedNode();
	void setCurrentScene( DiagramScene* );
	void setCurrentView( QGraphicsView* );
	virtual void createNewTab(std::string );

public slots:
	NodeItem * addMappingNode(QString );
	void showAttribute(NodeItem* );
	void updateMappingNode(QTreeWidgetItem* ,int );
	void adjustCheckboxState( QTreeWidgetItem* , int );
	void setPortValue(QTreeWidgetItem* ,int );
	void setExpandedState(QTreeWidgetItem* );
	void currentTabChange(int);
	virtual void closeTab(int );
	void cleanTreeWidget();
	void timerStart();
	void timerEnd();

protected:
	Ui::MappingDialogClass ui;
	
	
	// 因為可能會有很多組view跟scene
	// dialog必須知道目前在使用中的view與scene是哪一組，所以使用_currentView跟_currentScene來記錄目前使用的是哪一組
	DiagramScene* _currentScene;
	QGraphicsView* _currentView;
	AbstractManager* _currentManager;

	NodeItem* _currentSelectedNode;	// 紀錄目前被選取的是哪一個MappingNode
	std::tr1::shared_ptr<QColor> _canvasBackgroundColor;		// 畫布背景顏色
	int _timerId;
	QPushButton* _currentPressedButton;

	void setupVMButton(QHBoxLayout*, std::string);
	void init();
	virtual void initMenuBar() = 0;
	virtual void setConnection();
	virtual void initVMButtonTab();
	void initPortTabWidget();
	virtual void initEditArea();
	virtual void createOtherWidget();
	virtual void initCanvas();
	void setStyle();
	void createPortList( QTreeWidget* , std::vector<NodePort*>* );
	void cleanChildrenOfTreeWidget( QTreeWidget* );
	void createAttributeList( QTreeWidget* , std::vector<NodePort*>& );
	void setPortClassText( NodePort* , QTreeWidgetItem* );
	QString* curtailPortName( NodePort* );
	void adjustDisableState( QTreeWidgetItem* );
	DiagramScene* findSceneByTabIndex( int );
	void resizeEvent(QResizeEvent *);
	virtual void setWidgetDisable( bool );
	void setVMButtonDisable( bool );
	void deleteAllByTabIndex( int );
	void timerEvent( QTimerEvent* e );
	void removeVMButton();
	virtual AbstractManager* initManager()=0;
};

#endif // ABSTRACTMAPPINGWINDOW_H
